package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.api.QuestionApi;
import com.tanhua.db.mapper.QuestionMapper;
import com.tanhua.model.pojo.Question;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 查询通用设置中的陌生人问题
     * @param userId
     * @return
     */
    @Override
    public Question findByUserId(Long userId) {
        LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Question::getUserId, userId);
        Question question = questionMapper.selectOne(queryWrapper);
        return question;
    }

    /**
     * 通过数据访问层新增陌生人问题
     * @param question
     */
    @Override
    public void saveQuestion(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 通过数据访问层修改陌生人问题
     * @param question
     */
    @Override
    public void updateQuestion(Question question) {
        questionMapper.updateById(question);
    }
}
